﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMS_MAV.DTO.Reportlosses;
using WMS_MAV.DTO.Warehouse.Storage;
using static System.Net.WebRequestMethods;

namespace WMS_MAV.Controllers
{
    public class ReportlossesController : Controller
    {

        private readonly IConfiguration _configuration;
        public ReportlossesController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult ShowReportlossesView()
        {
            return View();
        }

        public IActionResult AddReportlossesView() { 
            return View();
        }

        public IActionResult UpdaetReportlossesView()
        {
            return View();
        }

        //报损显示
        [HttpGet]
        public async Task<ActionResult> GEtReportlossesShow(string token, string? reportlossesNo, string? reportlossesType,int? documentState, int index, int size)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "warehouseRead/api/Reportlosses/GetReportShow?index=" + index + "&size=" + size + "&reportlossesNo=" + reportlossesNo +
                "&reportlossesType=" + reportlossesType+ "&documentState=" + documentState; ;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }

        /// <summary>
        /// 报损添加
        /// </summary>
        /// <param name="token"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> ReportlossesAdd(string token, AddReportlossesDto data)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "warehouse/api/Reportlosses/AddReportlosses";
            string list = JsonConvert.SerializeObject(data);
            var respomse = await client.PostAsync(url, list);
            return Json(respomse);
        }

        /// <summary>
        /// 报损逻辑删除
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]  
        public async Task<ActionResult> ReportRangeDel(DeleteReportlossesDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+ "warehouse/api/Reportlosses/DelReportlosses";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }

        //报损查看详情
        [HttpGet]
        public async Task<ActionResult> ReportlossesDetails(string token,int reportlossesId)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "warehouseRead/api/Reportlosses/GetReportDetails?ReportlossesId=" + reportlossesId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }

        /// <summary>
        /// 审核报损管理
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> ReportlossesAuid(AuidReportlossesDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "warehouse/api/Reportlosses/ReportAuid";
            string list=JsonConvert.SerializeObject(dto);
            var response = await client.PostAsync(url,list);
            return Json(response);
        }


        /// <summary>
        /// 修改报损管理
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> ReportlossesUpdate(string token, UpdateReportlossesDto field)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "warehouse/api/Reportlosses/UpReportlosses";
            string list = JsonConvert.SerializeObject(field);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }


        /// <summary>
        /// 批量删除报损产品信息
        /// </summary>
        /// <param name="storageProductsId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> ReportProductRangeDel(RangeDelReportlossesDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "warehouse/api/Reportlosses/RepoRangeInfo";
            string list = JsonConvert.SerializeObject(dto);
            var response = await client.PostAsync(url,list);
            return Json(response);
        }
    }
}
